
package lab03.test03;

import java.io.*;

public class Test03 {
    public static void main(String[] args) {
        String path = "F:\\test.txt";
        File myFile = new File(path);
        try {
            myFile.createNewFile();
            System.out.println("创建文件成功！");
        } catch (IOException e) {
            e.printStackTrace();
        }
        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(path);
            fileOutputStream.write(new String("Beijing欢迎你！").getBytes());
            System.out.println("写入文件成功！");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(path);
            byte[] data = new byte[fileInputStream.available()];
            fileInputStream.read(data);
            String s = new String(data);
            System.out.println(s);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }



        path = "F:\\Hello.txt";
        FileOutputStream file = null;
        try {
            file = new FileOutputStream(path);
            file.write(new String("我的学号是：自己的学号").getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                file.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        //myFile.deleteOnExit();
    }
}
